function getCookie(key){
  const arr = document.cookie.split("; ")
  for(let i=0;i<arr.length;i++){
    const a = arr[i].split("=");
    if(a[0] === key){
      return a[1];
    }
  }
  return null;
}

function removeCookie(key, ops={}){
  ops.expires = -1;
  setCookie(key, "", ops);
}

function setCookie(key, val, ops={}){
  let exp = "";
  if(ops.expires){
    const d = new Date();
    d.setDate(d.getDate() + ops.expires );
    exp = `;expires=${d}`
  }
  let path = ops.path ? ";path=" + ops.path : "";
  document.cookie = `${key}=${val}${path}${exp}`;
}